#ifndef SMARTINGIMPEDANCEMETER_H
#define SMARTINGIMPEDANCEMETER_H

#include <QQuickItem>
#include <QThread>

#include "signalprocessing.h"
#include "signalprocessing/filter/butterfilter.h"

class SmartingImpedanceMeterWorker;

class SmartingImpedanceMeter : public QQuickItem
{
    Q_OBJECT

    friend class SmartingImpedanceMeterWorker;

    enum impedanceValue
    {
        LOW, MEDIUM, HIGH
    };

public:
    explicit SmartingImpedanceMeter(QQuickItem *parent = 0);

    /********************************************************
     * Function Name    :   registerTypes
     *
     * Description      :   Register SmartingImpedanceMeter class to QML
     *
     * Side effects     :
     *
     * Comment          :
     *
     * Parameters       :
     *
     * Returns      	:
     *
     * Reviewed by      :   v_duschan@hotmail.com
     *
     ********************************************************/
    static void registerTypes(const char *uri);

    Q_INVOKABLE bool init(int burstLength);

    Q_INVOKABLE bool start();

    Q_INVOKABLE EXPORT_SIGNAL(_inISig, ISignal)

signals:

public slots:

    private:
        int _burstLength;
        ISignal *_inISig;
        ISignal *_internalISig;

        QThread *_workerThread;
        SmartingImpedanceMeterWorker *_worker;

        float _thresholdLow = 10;
        float _thresholdHigh = 100;

        ButterFilter *_lowPass;
        ButterFilter *_highPass;

        impedanceValue _prevImpedance = LOW;
        int _refreshInterval = 0;
};
class SmartingImpedanceMeterWorker : public QObject
{
    Q_OBJECT

    friend class SmartingImpedanceMeter;

    /********************************************************/
    /*              Typedefs                                */
    /********************************************************/
    public:

    protected:

    private:

    /********************************************************/
    /*              Functions Declarations                  */
    /********************************************************/
    public:
        /********************************************************
         * Function Name    :   SmartingImpedanceMeterWorker
         *
         * Description      :   Constructor
         *
         * Side effects     :
         *
         * Comment          :
         *
         * Parameters       :
         *
         * Returns      	:
         *
         * Reviewed by      :   v_duschan@hotmail.com
         *
         ********************************************************/
        SmartingImpedanceMeterWorker(SmartingImpedanceMeter &context);

    public slots:

    protected:

    protected slots:

    private:

    private slots:
        void _start();

    /********************************************************/
    /*              Variables Declarations                  */
    /********************************************************/
    public:

    protected:

    private:
        SmartingImpedanceMeter &_context;
};

#endif // SMARTINGIMPEDANCEMETER_H
